import {
  SET_USERNAME,
  SET_PASSWORD,
  SET_IS_REMEMBER_PWD,
  SET_USER_INFO,
  INIT_USER_INFOS,
  SET_LANG,
} from "./actionTypes";

const actions = {
  [SET_USERNAME]({ commit }, username) {
    commit(SET_USERNAME, username);
  },
  [SET_PASSWORD]({ commit }, password) {
    commit(SET_PASSWORD, password);
  },
  [SET_IS_REMEMBER_PWD]({ commit }, isRememberPwd) {
    commit(SET_IS_REMEMBER_PWD, isRememberPwd);
  },
  [SET_USER_INFO]({ commit }, { key, value }) {
    commit(SET_USER_INFO, {
      key,
      value,
    });
  },
  [INIT_USER_INFOS]({ commit }) {
    commit(INIT_USER_INFOS);
  },

  [SET_LANG]({ commit }, payload) {
    if (!payload) {
      return;
    }
    const lang = payload.lang;
    commit(SET_LANG, lang);
  },
};

export default actions;
